package dao;

import common.Course;
import service.FlushCourse;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class LogoutCourse {
    private static Connection conn=DataBaseConnect.getConn();
    private static String sql="delete from course where id=?";
    private static PreparedStatement pstmt;
    static {
        try {
            pstmt=conn.prepareStatement(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static boolean logoutCourse(Course course){
        try {
            pstmt.setString(1,course.getId());
            int count=pstmt.executeUpdate();
            if(count==1){
                for(int i=0;i<course.getStudent().size();i++){
                    FlushCourse.flush(course.getStudent().get(i).getId());
                }
                FlushCourse.flush(course.getTeacherId());
                System.out.println("课程注销成功");
                return true;
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return false;
    }
}
